.class public Lnet/tsapps/topdeals/notificationservice/NotificationService;
.super Landroid/app/Service;


# static fields
.field private static c:Ljava/lang/String;

.field private static final h:[Ljava/lang/Class;

.field private static final i:[Ljava/lang/Class;


# instance fields
.field private a:Landroid/content/Context;

.field private b:Lnet/tsapps/topdeals/h/a;

.field private d:Ljava/lang/reflect/Method;

.field private e:Ljava/lang/reflect/Method;

.field private f:[Ljava/lang/Object;

.field private g:[Ljava/lang/Object;


# direct methods
.method static constructor <clinit>()V
    .locals 4

    const/4 v3, 0x1

    const/4 v2, 0x0

    const-string v0, "TD NotificationService"

    sput-object v0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->c:Ljava/lang/String;

    const/4 v0, 0x2

    new-array v0, v0, [Ljava/lang/Class;

    sget-object v1, Ljava/lang/Integer;->TYPE:Ljava/lang/Class;

    aput-object v1, v0, v2

    const-class v1, Landroid/app/Notification;

    aput-object v1, v0, v3

    sput-object v0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->h:[Ljava/lang/Class;

    new-array v0, v3, [Ljava/lang/Class;

    sget-object v1, Ljava/lang/Boolean;->TYPE:Ljava/lang/Class;

    aput-object v1, v0, v2

    sput-object v0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->i:[Ljava/lang/Class;

    return-void
.end method

.method public constructor <init>()V
    .locals 1

    invoke-direct {p0}, Landroid/app/Service;-><init>()V

    const/4 v0, 0x2

    new-array v0, v0, [Ljava/lang/Object;

    iput-object v0, p0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->f:[Ljava/lang/Object;

    const/4 v0, 0x1

    new-array v0, v0, [Ljava/lang/Object;

    iput-object v0, p0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->g:[Ljava/lang/Object;

    return-void
.end method


# virtual methods
.method public onBind(Landroid/content/Intent;)Landroid/os/IBinder;
    .locals 1

    const/4 v0, 0x0

    return-object v0
.end method

.method public onCreate()V
    .locals 3

    :try_start_0
    invoke-virtual {p0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v0

    const-string v1, "startForeground"

    sget-object v2, Lnet/tsapps/topdeals/notificationservice/NotificationService;->h:[Ljava/lang/Class;

    invoke-virtual {v0, v1, v2}, Ljava/lang/Class;->getMethod(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;

    move-result-object v0

    iput-object v0, p0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->d:Ljava/lang/reflect/Method;

    invoke-virtual {p0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v0

    const-string v1, "stopForeground"

    sget-object v2, Lnet/tsapps/topdeals/notificationservice/NotificationService;->i:[Ljava/lang/Class;

    invoke-virtual {v0, v1, v2}, Ljava/lang/Class;->getMethod(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;

    move-result-object v0

    iput-object v0, p0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->e:Ljava/lang/reflect/Method;
    :try_end_0
    .catch Ljava/lang/NoSuchMethodException; {:try_start_0 .. :try_end_0} :catch_0

    :goto_0
    invoke-virtual {p0}, Lnet/tsapps/topdeals/notificationservice/NotificationService;->getApplicationContext()Landroid/content/Context;

    move-result-object v0

    iput-object v0, p0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->a:Landroid/content/Context;

    invoke-super {p0}, Landroid/app/Service;->onCreate()V

    new-instance v0, Lnet/tsapps/topdeals/h/a;

    iget-object v1, p0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->a:Landroid/content/Context;

    invoke-direct {v0, v1}, Lnet/tsapps/topdeals/h/a;-><init>(Landroid/content/Context;)V

    iput-object v0, p0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->b:Lnet/tsapps/topdeals/h/a;

    sget-object v0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->c:Ljava/lang/String;

    const-string v1, "Notification Service initialized"

    invoke-static {v0, v1}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I

    return-void

    :catch_0
    move-exception v0

    const/4 v0, 0x0

    iput-object v0, p0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->e:Ljava/lang/reflect/Method;

    iput-object v0, p0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->d:Ljava/lang/reflect/Method;

    goto :goto_0
.end method

.method public onStart(Landroid/content/Intent;I)V
    .locals 9

    const/4 v6, 0x1

    :try_start_0
    sget-object v0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->c:Ljava/lang/String;

    const-string v1, "Checking for new deals"

    invoke-static {v0, v1}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I

    iget-object v0, p0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->b:Lnet/tsapps/topdeals/h/a;

    invoke-virtual {v0}, Lnet/tsapps/topdeals/h/a;->b()Lorg/json/JSONObject;

    move-result-object v3

    const-string v0, "latestid"

    invoke-virtual {v3, v0}, Lorg/json/JSONObject;->getInt(Ljava/lang/String;)I

    move-result v0

    int-to-long v0, v0

    iget-object v2, p0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->b:Lnet/tsapps/topdeals/h/a;

    invoke-virtual {v2}, Lnet/tsapps/topdeals/h/a;->d()J

    move-result-wide v4

    cmp-long v2, v0, v4

    if-lez v2, :cond_0

    iget-object v2, p0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->b:Lnet/tsapps/topdeals/h/a;

    invoke-virtual {v2, v0, v1}, Lnet/tsapps/topdeals/h/a;->a(J)V

    const-string v0, "amount"

    invoke-virtual {v3, v0}, Lorg/json/JSONObject;->getInt(Ljava/lang/String;)I

    move-result v0

    if-eqz v0, :cond_0

    new-instance v4, Landroid/content/Intent;

    iget-object v1, p0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->a:Landroid/content/Context;

    const-class v2, Lnet/tsapps/topdeals/DealListActivity;

    invoke-direct {v4, v1, v2}, Landroid/content/Intent;-><init>(Landroid/content/Context;Ljava/lang/Class;)V

    if-ne v0, v6, :cond_2

    const-string v0, "name"

    invoke-virtual {v3, v0}, Lorg/json/JSONObject;->getString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    const-string v0, "saving"

    invoke-virtual {v3, v0}, Lorg/json/JSONObject;->getInt(Ljava/lang/String;)I

    move-result v0

    if-nez v0, :cond_1

    const-string v1, "Deal anzeigen."

    move-object v0, v2

    :goto_0
    const-string v5, "itemid"

    const-string v6, "latestid"

    invoke-virtual {v3, v6}, Lorg/json/JSONObject;->getLong(Ljava/lang/String;)J

    move-result-wide v6

    invoke-virtual {v4, v5, v6, v7}, Landroid/content/Intent;->putExtra(Ljava/lang/String;J)Landroid/content/Intent;

    move-object v3, v2

    move-object v2, v1

    move-object v1, v0

    :goto_1
    iget-object v0, p0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->a:Landroid/content/Context;

    const/4 v5, 0x0

    const/4 v6, 0x0

    invoke-static {v0, v5, v4, v6}, Landroid/app/PendingIntent;->getActivity(Landroid/content/Context;ILandroid/content/Intent;I)Landroid/app/PendingIntent;

    move-result-object v4

    const-string v0, "notification"

    invoke-virtual {p0, v0}, Lnet/tsapps/topdeals/notificationservice/NotificationService;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Landroid/app/NotificationManager;

    new-instance v5, Landroid/app/Notification;

    const v6, 0x7f020029

    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v7

    invoke-direct {v5, v6, v1, v7, v8}, Landroid/app/Notification;-><init>(ILjava/lang/CharSequence;J)V

    iget-object v1, p0, Lnet/tsapps/topdeals/notificationservice/NotificationService;->a:Landroid/content/Context;

    invoke-virtual {v5, v1, v3, v2, v4}, Landroid/app/Notification;->setLatestEventInfo(Landroid/content/Context;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Landroid/app/PendingIntent;)V

    const/4 v1, 0x1

    invoke-virtual {v0, v1, v5}, Landroid/app/NotificationManager;->notify(ILandroid/app/Notification;)V
    :try_end_0
    .catch Ljava/lang/Throwable; {:try_start_0 .. :try_end_0} :catch_0

    :cond_0
    :goto_2
    invoke-virtual {p0}, Lnet/tsapps/topdeals/notificationservice/NotificationService;->stopSelf()V

    return-void

    :cond_1
    :try_start_1
    new-instance v1, Ljava/lang/StringBuilder;

    const-string v5, "Jetzt "

    invoke-direct {v1, v5}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v1, v0}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v0

    const-string v1, "% sparen."

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    new-instance v0, Ljava/lang/StringBuilder;

    invoke-static {v2}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v5

    invoke-direct {v0, v5}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v5, ". "

    invoke-virtual {v0, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    goto :goto_0

    :cond_2
    const/16 v1, 0xf

    if-le v0, v1, :cond_3

    const-string v0, "\u00dcber 15 neue Deals gefunden."

    :goto_3
    const-string v1, "Deals anzeigen."

    move-object v2, v1

    move-object v3, v0

    move-object v1, v0

    goto :goto_1

    :cond_3
    new-instance v1, Ljava/lang/StringBuilder;

    invoke-static {v0}, Ljava/lang/String;->valueOf(I)Ljava/lang/String;

    move-result-object v0

    invoke-direct {v1, v0}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v0, " neue Deals gefunden."

    invoke-virtual {v1, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
    :try_end_1
    .catch Ljava/lang/Throwable; {:try_start_1 .. :try_end_1} :catch_0

    move-result-object v0

    goto :goto_3

    :catch_0
    move-exception v0

    sget-object v1, Lnet/tsapps/topdeals/notificationservice/NotificationService;->c:Ljava/lang/String;

    invoke-virtual {v0}, Ljava/lang/Throwable;->getMessage()Ljava/lang/String;

    move-result-object v2

    invoke-static {v1, v2, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_2
.end method
